package com.woniuxy.purchasemanager.controller;

import com.woniuxy.commons.entity.purchaseManager.NeedEntity;
import com.woniuxy.commons.entity.purchaseManager.base.VoEntity;
import com.woniuxy.commons.result.Result;
import com.woniuxy.purchasemanager.service.DictService;
import com.woniuxy.purchasemanager.service.NeedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 提交需求
 *
 * @author huangzhichao
 * @email 1205560871@gmail.com
 * @date 2022-04-19 13:00:28
 */
@Api(tags = "提交需求")
@RestController
@RequestMapping("need/need")
public class NeedController {
    @Autowired
    private NeedService needService;


    @Resource
    private DictService dictService;

    //数据字典
    @GetMapping("/findAll")
    public Result all() {
        Map<String, Object> all = dictService.findAll();
        return Result.ok(all);
    }

    /**
     * 列表
     */

    @ApiOperation(value = "列表")
    @GetMapping("/list/{currentPage}/{pageSize}")

    public Result list(@PathVariable("currentPage") Integer currentPage,@PathVariable("pageSize") Integer pageSize) {
      VoEntity<NeedEntity> needAll = needService.pageList( currentPage,pageSize);
        return Result.ok(needAll);
    }


    @ApiOperation(value = "查询所有需求单列表")
    @GetMapping("/all")
    public Result<List<NeedEntity>> selectAll(){
        return Result.ok(needService.selectAll());
    }

    /**
     * 信息
     */
    @ApiOperation(value = "信息")
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Integer id) {
        NeedEntity need = needService.getById(id);

        return Result.ok(need);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public Result save(@RequestBody HashMap<String, Object> map) {
        boolean b = needService.saveGoodsAll(map);
        return Result.ok(b);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody NeedEntity need) {
        needService.updateById(need);
        return Result.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody Integer[] ids) {
        needService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
